package com.novellotus.iov.carvice.adapter;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.ShapeDrawable;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.novellotus.iov.carvice.R;
import com.novellotus.iov.carvice.bean.RxEinfos;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Rich on 2017/12/25.
 *
 */

public class HomePageRoleAdapter extends RecyclerView.Adapter<HomePageRoleAdapter.RoleHolder> {

    private Context context;
    private List<RxEinfos.RolesBean> rolesBeanList;

    public HomePageRoleAdapter(List<RxEinfos.RolesBean> rolesBeanList) {
        this.rolesBeanList = rolesBeanList;
    }

    @Override
    public RoleHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        context = parent.getContext();
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_home_role, null);
        return new RoleHolder(view);
    }

    @Override
    public void onBindViewHolder(RoleHolder holder, int position) {
        if(rolesBeanList.get(position)!=null){
            holder.tv_role.setText(rolesBeanList.get(position).getRoleName());
            if(rolesBeanList.get(position).getBackColor()!=null){
                holder.tv_role.setTextColor(Color.parseColor(rolesBeanList.get(position).getBackColor()));
                holder.tv_role.setBackground(context.getResources().getDrawable(R.drawable.shape_vehicle_box));
                GradientDrawable bgShape = (GradientDrawable) holder.tv_role.getBackground();
                bgShape.setStroke((int)context.getResources().getDimension(R.dimen.shape_line), Color.parseColor(rolesBeanList.get(position).getBackColor()));
            }else{
                holder.tv_role.setTextColor(Color.parseColor("#fecf5d"));
                holder.tv_role.setBackground(context.getResources().getDrawable(R.drawable.shape_vehicle_box));
                GradientDrawable bgShape = (GradientDrawable) holder.tv_role.getBackground();
                bgShape.setStroke((int)context.getResources().getDimension(R.dimen.shape_line), Color.parseColor("#fecf5d"));
            }
        }
    }


    @Override
    public int getItemCount() {
        return rolesBeanList.size();
    }

    class RoleHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.tv_role)
        TextView tv_role;

        RoleHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
